package org.flexthinker.binding.bean
{
    /**
     * <code>SyncFailure</code> represents a failure to sync a <code>Binding</code>.
     * Bindings tries to sync when calling <code>save()</code> or <code>refresh()</code>
     *
     * @see Binding
     * @see Binding#save
     * @see Binding#refresh
     */
    public class SyncFailure
    {
        public static const TARGET_UNWRITEABLE:SyncFailure = new SyncFailure().ofType(SyncFailureType.TARGET_UNWRITEABLE);
        public static const SOURCE_UNWRITEABLE:SyncFailure = new SyncFailure().ofType(SyncFailureType.SOURCE_UNWRITEABLE);

        public static const TARGET_UNREADABLE:SyncFailure = new SyncFailure().ofType(SyncFailureType.TARGET_UNREADABLE);
        public static const SOURCE_UNREADABLE:SyncFailure = new SyncFailure().ofType(SyncFailureType.SOURCE_UNREADABLE);

        private var type:String;
        private var error:Error;

        public function SyncFailure( error:Error=null)
        {
            this.error = error;
        }

        public function ofType(type:String):SyncFailure
        {
            this.type = type;
            return this;
        }

        public function getType():String
        {
            return type;
        }

        public function getError():Error
        {
            return error;
        }
    }
}
